package com.platform.tony.config;


import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;


/**
 * 邮箱登录 token
 * 1 AbstractAuthenticationToken
 * 2 AbstractAuthenticationProcessingFilter
 *
 */
@Getter
@Setter
public class EmailAuthToken extends AbstractAuthenticationToken implements Serializable {

    private static final long serialVersionUID = -5750459487308458785L;


    private Collection<GrantedAuthority> authorities = new ArrayList<>();
    // 登录之前是用户名 登录后是用户信息
    private Object principal;
    private Object credentials;

    public EmailAuthToken(Object principal) {
        super(null);
        this.principal = principal;
        // 是否向 authenticationManager 提供身份验证令牌
        setAuthenticated(false);
    }

    public EmailAuthToken(Object principal, Collection<GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        // 是否向 authenticationManager 提供身份验证令牌
        setAuthenticated(true);
    }


    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }


}
